package com.wnd.dell.myapplication;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TrainAdapter extends BaseAdapter {

    private Context mContext1;
    private TrainDate trainDate;

    public TrainAdapter(Context context) {this.mContext1 = context;}
    public void setData(TrainDate trainDate) {
        this.trainDate = trainDate;
        this.notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        if (trainDate == null) {
            return 0;
        } else {
            return trainDate.getResult().getStation_list().size();
        }
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        System.out.println("getView " + position + " " + convertView);
        TrainAdapter.ViewHolder11 holder = null;
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(mContext1);
            convertView = inflater.inflate(R.layout.item2_layout, null);
            holder = new TrainAdapter.ViewHolder11();
            holder.textView = (TextView) convertView.findViewById(R.id.tv_Train_id);
            holder.textView2 = (TextView) convertView.findViewById(R.id.tv_Arrived_time);
            holder.textView3 = (TextView) convertView.findViewById(R.id.tv_Station_name);
            holder.textView4 = (TextView) convertView.findViewById(R.id.tv_Leave_time);
            holder.textView5 = (TextView) convertView.findViewById(R.id.tv_HardSleep);
            holder.imageView = (ImageView) convertView.findViewById(R.id.iv_head);
            convertView.setTag(holder);
        } else {
            holder = (TrainAdapter.ViewHolder11) convertView.getTag();
        }
        holder.textView.setText(trainDate.getResult().getStation_list().get(position).getTrain_id());
        holder.textView2.setText(trainDate.getResult().getStation_list().get(position).getArrived_time());
        holder.textView3.setText(trainDate.getResult().getStation_list().get(position).getStation_name());
        holder.textView4.setText(trainDate.getResult().getStation_list().get(position).getLeave_time());
        holder.textView5.setText(trainDate.getResult().getStation_list().get(position).getHardSleep());
        return convertView;

    }

    public static class ViewHolder11 {
        public TextView textView;
        public TextView textView2;
        public TextView textView3;
        public TextView textView4;
        public TextView textView5;
        public ImageView imageView;
    }
}
